﻿using System.Collections;
using System.Collections.Generic;

using Entitas;

using UnityEngine;

namespace Internal
{
    /// <summary>
    /// 响应鼠标右键 ，移动物体
    /// </summary>
    public class StarMoveSystem : ReactiveSystem<InputEntity>
    {
        private GameContext _gameContext;

        private IGroup<GameEntity> moveGroup;

        public StarMoveSystem(Contexts contexts) : base(contexts.input)
        {
            _gameContext = contexts.game;
            moveGroup = contexts.game.GetGroup(GameMatcher.InternalView);
        }

        protected override void Execute(List<InputEntity> entities)
        {
            foreach (InputEntity item in entities)
            {
                Vector2 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                foreach (GameEntity  game in moveGroup)
                {
                    game.ReplaceInternalMove(pos);
                }
            }
        }

        protected override bool Filter(InputEntity entity)
        {
            return entity.hasInternalMouseEvent
                 && entity.internalMouseEvent.clickEvent == MouseClickEvent.DOWN
                && entity.internalMouseEvent.mouseEvent == MouseEvent.RIGHT;
        }

        protected override ICollector<InputEntity> GetTrigger(IContext<InputEntity> context)
        {
            return context.CreateCollector(InputMatcher.InternalMouseEvent);
        }
    }
}

